Chapter 4
Dates and Times
<xsl:call-template name="ckbk:calculate-day-of-the-week">
     <xsl:with-param name="date-time" select="'2002-01-01T01:00:00'"/>
</xsl:call-template>
   
<xsl:call-template name="ckbk:calculate-day-of-the-week">
     <xsl:with-param name="date" select="'2002-01-01'"/>
</xsl:call-template>
   
<xsl:call-template name="ckbk:calculate-day-of-the-week">
     <xsl:with-param name="year" select="2002"/>
     <xsl:with-param name="month" select="01"/>
     <xsl:with-param name="day" select="01"/>
</xsl:call-template>
<xsl:call-template name="ckbk:calculate-day-of-the-week">
     <xsl:with-param name="date" select="'2002-01-01'"/>
     <xsl:with-parm name="day" select="25"/>
</xsl:call-template>
1) Calculating the Day of the Week
XSLT 1.0
  <xsl:template name="ckbk:calculate-day-of-the-week">
    <xsl:param name="date-time"/>
    <xsl:param name="date" select="substring-before($date-time,'T')"/>
    <xsl:param name="year" select="substring-before($date,'-')"/>
    <xsl:param name="month" 
          select="substring-before(substring-after($date,'-'),'-')"/>
    <xsl:param name="day" select="substring-after(substring-after($date,'-'),'-
')"/>
    
    <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
    <xsl:variable name="y" select="$year - $a"/>
    <xsl:variable name="m" select="$month + 12 * $a - 2"/>
   
    <xsl:value-of select="($day + $y + floor($y div 4) - floor($y div 100) 
    + floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>
   
  </xsl:template>
2) Determining the Last Day of the Month
XSLT 1.0
<xsl:template name="ckbk:last-day-of-month">
     <xsl:param name="month"/>
     <xsl:param name="year"/>
     <xsl:choose>
       <xsl:when test="$month = 2 and 
          not($year mod 4) and 
          ($year mod 100 or not($year mod 400))">
         <xsl:value-of select="29"/>
          </xsl:when>
       <xsl:otherwise>
         <xsl:value-of 
          select="substring('312831303130313130313031',
                         2 * $month - 1,2)"/>
       </xsl:otherwise>
     </xsl:choose>
</xsl:template>
XSLT 2.0
<xsl:function name="ckbk:last-day-of-month" as="xs:integer">

    <xsl:param name="month" as="xs:integer"/>
    <xsl:param name="year" as="xs:integer"/>

	<!--First of the month in given year -->
    <xsl:variable name="date" 
			select="xs:date(concat(xs:string($year),
			 			'-',format-number($month,'00'),'-01'))"
			as="xs:date"/>

    <xsl:variable name="m" 
			select="xdt:yearMonthDuration('P1M')" 
			as="xdt:yearMonthDuration"/>

    <xsl:variable name="d" 
			select="xdt:dayTimeDuration('P1D')" 
			as="xdt:dayTimeDuration"/>
 
    <xsl:sequence select="day-from-date(($date + $m) - $d)"/>

</xsl:function> 
3) Getting Names for Days and Months
XSLT 1.0
  <xsl:template name="ckbk:get-day-of-the-week-name">
    <xsl:param name="day-of-the-week"/>
   
    <xsl:choose>
      <xsl:when test="$day-of-the-week = 0">Sunday</xsl:when>
      <xsl:when test="$day-of-the-week = 1">Monday</xsl:when>
      <xsl:when test="$day-of-the-week = 2">Tuesday</xsl:when>
      <xsl:when test="$day-of-the-week = 3">Wednesday</xsl:when>
      <xsl:when test="$day-of-the-week = 4">Thursday</xsl:when>
      <xsl:when test="$day-of-the-week = 5">Friday</xsl:when>
      <xsl:when test="$day-of-the-week = 6">Saturday</xsl:when>
      <xsl:otherwise>
          error: <xsl:value-of select="$day-of-the-week"/>
        </xsl:otherwise>
    </xsl:choose>
   
  </xsl:template>
   
   <xsl:template name="ckbk:get-day-of-the-week-abbreviation">
    <xsl:param name="day-of-the-week"/>
   
    <xsl:choose>
      <xsl:when test="$day-of-the-week = 0">Sun</xsl:when>
      <xsl:when test="$day-of-the-week = 1">Mon</xsl:when>
      <xsl:when test="$day-of-the-week = 2">Tue</xsl:when>
      <xsl:when test="$day-of-the-week = 3">Wed</xsl:when>
      <xsl:when test="$day-of-the-week = 4">Thu</xsl:when>
      <xsl:when test="$day-of-the-week = 5">Fri</xsl:when>
      <xsl:when test="$day-of-the-week = 6">Sat</xsl:when>
      <xsl:otherwise>
          error: <xsl:value-of select="$day-of-the-week"/>
        </xsl:otherwise>
    </xsl:choose>
   
  </xsl:template>
   
  <xsl:template name="ckbk:get-month-name">
    <xsl:param name="month"/>
   
    <xsl:choose>
      <xsl:when test="$month = 1">January</xsl:when>
      <xsl:when test="$month = 2">February</xsl:when>
      <xsl:when test="$month = 3">March</xsl:when>
      <xsl:when test="$month = 4">April</xsl:when>
      <xsl:when test="$month = 5">May</xsl:when>
      <xsl:when test="$month = 6">June</xsl:when>
      <xsl:when test="$month = 7">July</xsl:when>
      <xsl:when test="$month = 8">August</xsl:when>
      <xsl:when test="$month = 9">September</xsl:when>
      <xsl:when test="$month = 10">October</xsl:when>
      <xsl:when test="$month = 11">November</xsl:when>
      <xsl:when test="$month = 12">December</xsl:when>
      <xsl:otherwise>error: <xsl:value-of select="$month"/></xsl:otherwise>
    </xsl:choose>
   
  </xsl:template>
   
  <xsl:template name="ckbk:get-month-abbreviation">
    <xsl:param name="month"/>
   
    <xsl:choose>
      <xsl:when test="$month = 1">Jan</xsl:when>
      <xsl:when test="$month = 2">Feb</xsl:when>
      <xsl:when test="$month = 3">Mar</xsl:when>
      <xsl:when test="$month = 4">Apr</xsl:when>
      <xsl:when test="$month = 5">May</xsl:when>
      <xsl:when test="$month = 6">Jun</xsl:when>
      <xsl:when test="$month = 7">Jul</xsl:when>
      <xsl:when test="$month = 8">Aug</xsl:when>
      <xsl:when test="$month = 9">Sep</xsl:when>
      <xsl:when test="$month = 10">Oct</xsl:when>
      <xsl:when test="$month = 11">Nov</xsl:when>
      <xsl:when test="$month = 12">Dec</xsl:when>
      <xsl:otherwise>error: <xsl:value-of select="$month"/></xsl:otherwise>
    </xsl:choose>
   
  </xsl:template>
XSLT 2.0
<xsl:function name="ckbk:get-day-of-the-week-name" as="xs:string">
  <xsl:param name="day-of-the-week" as="xs:integer"/>

  <!-- Any old Sunday will do as the base. Here I arbitraily picked 
       Sunday, Aug 14 2005 as my base date because it happens to be the 
       day I am writing this-->

  <xsl:variable name="date" 
        select="concat('2005-08-', string(14 + $day-of-the-week))" as="xs:date"/>
   
  <xsl:sequence select="format-date($date,"[F]"/>
</xsl:function>
   
<xsl:function name="ckbk:get-day-of-the-week-name-abbr" as="xs:string">
  <xsl:param name="day-of-week" as="xs:integer"/>

  <xsl:variable name="date" 
        select="concat('2005-08-', string(14 + $day-of-the-week))" as="xs:date"/>

  <xsl:sequence select="format-date($date, '[FNn,3-3]')"/>
    
</xsl:function>   

<xsl:function name="ckbk:get-month-name" as="xs:string">
  <xsl:param name="month" as="xs:integer"/>

  <xsl:variable name="jan01" select="xs:date('2005-01-01')" as="xs:date"/>

  <!-- Here we use date+duration math rather than string manipulation to get
       the date we need for format-date --> 
  <xsl:sequence select="format-date($jan01 +
       xdt:yearMonthDuration(concat('P',$month - 1,'M')), '[MNn]')"/>
    
</xsl:function>   

<xsl:function name="ckbk:get-month-name-abbr" as="xs:string">
  <xsl:param name="month" as="xs:integer"/>

  <xsl:variable name="jan01" select="xs:date('2005-01-01')" as="xs:date"/>

  <xsl:sequence 
     select="format-date($jan01 + 
               xdt:yearMonthDuration(concat('P',$month - 1,'M')), '[MNn,3-3]')"/>    

</xsl:function>     
Discussion
XSLT 1.0
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:date="http://www.ora.com/XSLTCookbook/NS/dates">
   
<!-- United States : us -->
<ckbk:month country="us" m="1"  name="January" abbrev="Jan" />
<ckbk:month country="us" m="2"  name="February" abbrev="Feb"/>
<ckbk:month country="us" m="3"  name="March" abbrev="Mar"/>
<ckbk:month country="us" m="4"  name="April" abbrev="Apr"/>
<ckbk:month country="us" m="5"  name="May" abbrev="May"/>
<ckbk:month country="us" m="6"  name="June" abbrev="Jun"/>
<ckbk:month country="us" m="7"  name="July" abbrev="Jul"/>
<ckbk:month country="us" m="8"  name="August" abbrev="Aug"/>
<ckbk:month country="us" m="9"  name="September" abbrev="Sep"/>
<ckbk:month country="us" m="10" name="October" abbrev="Oct"/>
<ckbk:month country="us" m="11" name="November" abbrev="Nov"/>
<ckbk:month country="us" m="12" name="December" abbrev="Dec"/>
   
<!-- Germany : de -->
<ckbk:month country="de" m="1"  name="Januar" abbrev="Jan"/>
<ckbk:month country="de" m="2"name=";Februar" abbrev="Feb"/>
<ckbk:month country="de" m="3"  name="Mrz" abbrev="Mr"/>
<ckbk:month country="de" m="4"  name="April" abbrev="Apr"/>
<ckbk:month country="de" m="5"  name="Mai" abbrev="Mai"/>
<ckbk:month country="de" m="6"  name="Juni" abbrev="Jun"/>
<ckbk:month country="de" m="7"  name="Juli" abbrev="Jul"/>
<ckbk:month country="de" m="8"  name="August" abbrev="Aug"/>
<ckbk:month country="de" m="9"  name="September" abbrev="Sep"/>
<ckbk:month country="de" m="10" name="Oktober" abbrev="Okt"/>
<ckbk:month country="de" m="11" name="November" abbrev="Nov"/>
<ckbk:month country="de" m="12" name="Dezember" abbrev="Dez"/>
<!-- You get the idea ... -->
   
<!-- Store element in variable for easy access -->
<xsl:variable name="ckbk:months" select="document('')/*/ckbk:month"/>
   
</xsl:stylesheet>
   
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:date="http://www.ora.com/XSLTCookbook/dates">
   
<xsl:include href="date-conversion.xsl"/>
   
<xsl:template name="ckbk:get-month-name">
     <xsl:param name="month"/>
     <xsl:param name="country" select=" 'us' "/>
   
     <xsl:value-of select="$ckbk:months[@country=$country and 
          @m=$month]/@name"/>
</xsl:template>
4) Calculating Julian and Absolute Day 
Numbers from a Specified Date
XSLT 1.0
<xsl:template name="ckbk:calculate-julian-day">
     <xsl:param name="year"/>
     <xsl:param name="month"/>
     <xsl:param name="day"/>
   
    <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
    <xsl:variable name="y" select="$year + 4800 - $a"/>
    <xsl:variable name="m" select="$month + 12 * $a - 3"/>
   
    <xsl:value-of select="$day + floor((153 * $m + 2) div 5) + $y * 365 + 
          floor($y div 4) - floor($y div 100) + floor($y div 400) - 
          32045"/>
   
  </xsl:template>
<xsl:template name="ckbk:date-difference">
     <xsl:param name="from-year"/>
     <xsl:param name="from-month"/>
     <xsl:param name="from-day"/>
     <xsl:param name="to-year"/>
     <xsl:param name="to-month"/>
     <xsl:param name="to-day"/>
   
     <xsl:variable name="jd1">
        <xsl:call-template name="ckbk:calculate-julian-day">
         <xsl:with-param name="year" select="$from-year"/>
           <xsl:with-param name="month" select="$from-month"/>
           <xsl:with-param name="day" select="$from-day"/>
       </xsl:call-template>
     </xsl:variable>
   
     <xsl:variable name="jd2">
        <xsl:call-template name="ckbk:calculate-julian-day">
         <xsl:with-param name="year" select="$to-year"/>
           <xsl:with-param name="month" select="$to-month"/>
           <xsl:with-param name="day" select="$to-day"/>
       </xsl:call-template>
     </xsl:variable>
   
     <xsl:value-of select="$jd1 - $jd2"/>
</xsl:template>
<xsl:template name="ckbk:julian-day-to-julian-date">
     <xsl:param name="j-day"/>
   
     <xsl:call-template name="ckbk:julian-or-gregorian-date-elem">
          <xsl:with param name="b" select="0"/>
          <xsl:with param name="c" select="$j-day + 32082"/>
     </xsl:call-template>
   
</xsl:template>
   
<xsl:template name="ckbk:julian-day-to-gregorian-date">
     <xsl:param name="j-day"/>
   
     <xsl:variable name="a" select="$j-day + 32044"/>
     <xsl:variable name="b" select="floor((4 * $a + 3) div 146097)"/>
     <xsl:variable name="c" select="$a - 146097 * floor($b div 4)"/>
   
     <xsl:call-template name="ckbk:julian-or-gregorian-date-elem">
          <xsl:with param name="b" select="$b"/>
          <xsl:with param name="c" select="$c"/>
     </xsl:call-template>
     
   
</xsl:template>
   
<!-- A utility that is used for both Gregorian and Julian calendars. -->
<xsl:template name="ckbk:julian-or-gregorian-date-elem">
     <xsl:param name="b"/>
     <xsl:param name="c"/>
   
     <xsl:variable name="d" select="floor((4 * $c + 3) div 1461)"/>
     <xsl:variable name="e" select="$c - floor((1461 * $d) div 4)"/>
     <xsl:variable name="m" select="floor((5 * $e + 2) div 153)"/>
   
     <xsl:variable name="day" 
          select="$e - floor((153 * $m + 2) div 5) + 1"/>
   
     <xsl:variable name="month" 
          select="$m + 3 - (12 * floor($m div 10))"/>
   
     <xsl:variable name="year" 
          select="100 * $b + $d - 4800 + floor($m div 10)"/>
   
     <xsl:value-of select="concat($year,'/',$month,'/',$day)"/>
     
</xsl:template>
<xsl:template name="ckbk:julian-day-to-absolute-day">
     <xsl:param name="j-day"/>
     <xsl:value-of select="$j-day - 1721425"/>
</xsl:template>
   
<xsl:template name="ckbk:absolute-day-to-julian-day">
     <xsl:param name="abs-day"/>
     <xsl:value-of select="$abs-day + 1721425"/>
</xsl:template>
<xsl:template name="ckbk:date-to-absolute-day">
    <xsl:param name="year"/>
    <xsl:param name="month"/>
    <xsl:param name="day"/>
    
    <xsl:call-template name="ckbk:julian-day-to-absolute-day">
      <xsl:with-param name="j-day">
        <xsl:call-template name="ckbk:date-to-julian-day">
          <xsl:with-param name="year" select="$year"/>
          <xsl:with-param name="month" select="$month"/>
          <xsl:with-param name="day" select="$day"/>
        </xsl:call-template>
      </xsl:with-param>
  </xsl:call-template>
</xsl:template>
   
<xsl:template name="ckbk:absolute-day-to-date">
  <xsl:param name="abs-day"/>
  
  <xsl:call-template name="ckbk:julian-day-to-date">
       <xsl:with-param name="j-day">
            <xsl:call-template name="ckbk:absolute-day-to-julian-day">
                 <xsl:with-param name="abs-day" select="$abs-day"/>
            </xsl:call-template>
       </xsl:with-param>
  </xsl:call-template>
</xsl:template>
XSLT 2.0
<dateDiff> 
<xsl:value-of select="xs:date('2005-02-21') - xs:date('2005-01-01')"/> 
</dateDiff>
<dateDiff>P51D</dateDiff>
<xsl:function name="ckbk:calculate-julian-day">
   <xsl:param name="date" as="xs:date"/>
     
   <xsl:variable name="year" select="year-from-date($date)"  as="xs:integer"/>
   <xsl:variable name="month" select="month-from-date($date)" as="xs:integer"/>
   <xsl:variable name="day" select="month-from-date($date)" as="xs:integer"/>
   
   <xsl:variable name="a" select="(14 - $month) idiv 12" as="xs:integer"/>
   <xsl:variable name="y" select="$year + 4800 - $a" as="xs:integer"/>
   <xsl:variable name="m" select="$month + 12 * $a - 3" as="xs:integer"/>
   
   <xsl:sequence select="$day + ((153 * $m + 2) idiv 5) + $y * 365 + 
        floor($y div 4) - ($y idiv 100) + ($y idiv 400) - 32045"/>
   
</xsl:function>
5) Calculating the Week Number for a 
Specified Date
XSLT 1.0
  <xsl:template name="ckbk:calculate-week-number">
    <xsl:param name="year"/>
    <xsl:param name="month"/>
    <xsl:param name="day"/>
   
    <xsl:variable name="ckbk:j-day">
      <xsl:call-template name="ckbk:calculate-julian-day">
        <xsl:with-param name="year" select="$year"/>
        <xsl:with-param name="month" select="$month"/>
        <xsl:with-param name="day" select="$day"/>
      </xsl:call-template>
    </xsl:variable>
   
    <xsl:variable name="d4" 
          select="($j-day + 31741 - ($j-day mod 7)) 
               mod 146097 mod 36524 mod 1461"/>
   
    <xsl:variable name="L" select="floor($d4 div 1460)"/>
   
    <xsl:variable name="d1" select="(($d4 - $L) mod 365) + $L"/>
   
    <xsl:value-of select="floor($d1 div 7) + 1"/>
   
  </xsl:template>
XSLT 2.0
<xsl:function name="ckbk:calculate-week-number" as="xs:integer">
  <xsl:param name="date" as="xs:date"/>
  <xsl:sequence select="xs:integer(format-date($date,'[W]'))"/>
</xsl:function>
6) Working with the Julian Calendar
Solution
<xsl:template name="ckbk:julian-date-to-julian-day">
    <xsl:param name="year"/>
    <xsl:param name="month"/>
    <xsl:param name="day"/>
   
    <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
    <xsl:variable name="y" select="$year + 4800 - $a"/>
    <xsl:variable name="m" select="$month + 12 * $a - 3"/>
   
    <xsl:value-of 
        select="$day + floor((153 * $m + 2) div 5) + 365 * $y 
        + floor($y div 4) - 32083"/>
   
  </xsl:template>
7) Working with the ISO Calendar
<xsl:template name="ckbk:k-day-on-or-before-abs-day">
     <xsl:param name="abs-day"/>
     <xsl:param name="k"/>
     <xsl:value-of select="$abs-day - (($abs-day - $k) mod 7)"/>
</xsl:template>
<xsl:template name="ckbk:iso-date-to-absolute-day">
     <xsl:param name="iso-week"/>
     <xsl:param name="iso-day"/>
     <xsl:param name="iso-year"/>
     
     <xsl:variable name="jan-4-of-year">
        <xsl:call-template name="ckbk:date-to-absolute-day">
         <xsl:with-param name="year" select="$iso-year"/>
          <xsl:with-param name="month" select="1"/>
          <xsl:with-param name="day" select="4"/>
         </xsl:call-template>
     </xsl:variable>
   
     <xsl:variable name="days-in-prior-yrs">
       <xsl:call-template name="ckbk:k-day-on-or-before-abs-day">
         <xsl:with-param name="abs-day" select="$jan-4-of-year"/>
         <xsl:with-param name="k" select="1"/>
       </xsl:call-template>
     </xsl:variable>
   
     <xsl:variable name="days-in-prior-weeks-this-yr"     
          select="7 * ($iso-week - 1)"/>
   
     <xsl:variable name="prior-days-this-week" select="$iso-day - 1"/>
   
     <xsl:value-of select="$days-in-prior-yrs + 
          $days-in-prior-weeks-this-yr + $prior-days-this-week"/>     
</xsl:template>
<xsl:template name="ckbk:absolute-day-to-iso-date">
     <xsl:param name="abs-day"/>
     
     <xsl:variable name="d">
       <xsl:call-template name="ckbk:absolute-day-to-date">
         <xsl:with-param name="abs-day" select="$abs-day - 3"/>
       </xsl:call-template>
     </xsl:variable>
     
     <xsl:variable name="approx" select="substring-before($d,'/')"/>
     
     <xsl:variable name="iso-year">
       <xsl:variable name="a">
         <xsl:call-template name="ckbk:iso-date-to-absolute-day">
          <xsl:with-param name="iso-week" select="1"/>
          <xsl:with-param name="iso-day" select="1"/>
          <xsl:with-param name="iso-year" select="$approx + 1"/>
         </xsl:call-template>
       </xsl:variable>
       <xsl:choose>
         <xsl:when test="$abs-day >= $a">
          <xsl:value-of select="$approx + 1"/>
         </xsl:when>
         <xsl:otherwise>
          <xsl:value-of select="$approx"/>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:variable>
   
     <xsl:variable name="ckbk:iso-week">
       <xsl:variable name="a">
         <xsl:call-template name="ckbk:iso-date-to-absolute-day">
           <xsl:with-param name="iso-week" select="1"/>
           <xsl:with-param name="iso-day" select="1"/>
           <xsl:with-param name="iso-year" select="$iso-year"/>
         </xsl:call-template>
      </xsl:variable>
       <xsl:value-of select="1 + floor(($abs-day - $a) div 7)"/>
     </xsl:variable>
     
     <xsl:variable name="iso-day">
       <xsl:variable name="a" select="$abs-day mod 7"/>
         <xsl:choose>
          <xsl:when test="not($a)">
            <xsl:value-of select="7"/>
          </xsl:when>
          <xsl:otherwise>
                    <xsl:value-of select="$a"/>
               </xsl:otherwise>
          </xsl:choose>
     </xsl:variable>
   
     <xsl:value-of select="concat($iso-year,'-W',$iso-week,'-',$iso-day)"/>
          
</xsl:template>
8) Working with the Islamic Calendar
<xsl:template name="ckbk:last-day-of-islamic-month">
     <xsl:param name="month"/>
     <xsl:param name="year"/>
     
     <xsl:variable name="islamic-leap-year" 
          select="(11 * $year + 14) mod 30 &lt; 11"/>
     
     <xsl:choose>
       <xsl:when test="$month mod 2 or ($month = 12 and $islamic-leap-year)">
         <xsl:value-of select="30"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="29"/>
       </xsl:otherwise>
     </xsl:choose>
</xsl:template>
<xsl:template name="ckbk:islamic-date-to-absolute-day">
    <xsl:param name="year"/>
    <xsl:param name="month"/>
    <xsl:param name="day"/>
    
    <xsl:value-of select="$day + 29 * ($month - 1) + floor($month div 2) + 354 
        * ($year - 1) + floor((11 * $year + 3) div 30) + 227014"/>
</xsl:template>
<xsl:template name="ckbk:absolute-day-to-islamic-date">
    <xsl:param name="abs-day"/>
   
     
     <xsl:variable name="year" 
          select="floor(($abs-day - 227014) div 354.36667) + 1"/>
     
     <xsl:variable name="month">
       <xsl:variable name="a" 
          select="$abs-day - 227014 - floor((11 * $year + 3) div 30) -
                 354 * ($year - 1)"/>
       <xsl:variable name="approx" select="floor($a div 29.53056)+1"/>
       <xsl:choose>
         <xsl:when test="(29 * ($approx - 1) + floor($approx div 2)) - 
          $a &lt; 1">
          <xsl:value-of select="$approx - 1"/>
         </xsl:when>
         <xsl:otherwise>
          <xsl:value-of select="$approx"/>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:variable>
     
     <xsl:variable name="day">
       <xsl:variable name="a">
         <xsl:call-template name="ckbk:islamic-date-to-absolute-day">
          <xsl:with-param name="year" select="$year"/>
          <xsl:with-param name="month" select="$month"/>
          <xsl:with-param name="day" select="1"/>
         </xsl:call-template>
       </xsl:variable>
       <xsl:value-of select="$abs-day - $a + 1"/>
     </xsl:variable>
     
     <xsl:value-of select="concat($year,'/',$month,'/',$day)"/>
     
</xsl:template>
9) Working with the Hebrew Calendar
<xsl:template name="ckbk:last-month-of-hebrew-year">
     <xsl:param name="year"/>
     <xsl:choose>
          <xsl:when test="(7 * $year + 1) mod 19 &lt; 7">
               <xsl:value-of select="13"/>
          </xsl:when>
          <xsl:otherwise>
               <xsl:value-of select="12"/>
          </xsl:otherwise>
     </xsl:choose>
</xsl:template>
<!-- Number of days elapsed from the Sunday prior to the start of the Hebrew 
calender to the mean conjunction of Tishri of Hebrew year. -->
   
<xsl:template name="ckbk:hebrew-calendar-elapsed-days">
     <xsl:param name="year"/>
   
     <xsl:variable name="hebrew-leap-year" 
          select="(7 * $year + 1) mod 19 &lt; 7"/>
     <xsl:variable name="hebrew-leap-year-last-year" 
          select="(7 * ($year - 1) + 1) mod 19 &lt; 7"/>
     
     <xsl:variable name="months-elapsed" 
          select="235 * floor(($year -1) div 19) +
               12 * (($year -1) mod 19) +
               floor((7 * (($year - 1) mod 19) + 1) div 19)"/>
   
     <xsl:variable name="parts-elapsed" 
          select="13753 * $months-elapsed + 5604"/>
   
     <xsl:variable name="day" select="1 + 29 * $months-elapsed + 
                    floor($parts-elapsed div 25920)"/>
   
     <xsl:variable name="parts" select="$parts-elapsed mod 25920"/>
     
     <xsl:variable name="alternative-day">
       <xsl:choose>
         <xsl:when test="$parts >= 19440">
          <xsl:value-of select="$day + 1"/>
         </xsl:when>
         <xsl:when test="$day mod 7 = 2 and $parts >= 9924 and 
               not($hebrew-leap-year)">
          <xsl:value-of select="$day + 1"/>
         </xsl:when>
         <xsl:when test="$day mod 7 = 1 and $parts >= 16789 and 
               $hebrew-leap-year-last-year">
          <xsl:value-of select="$day + 1"/>
         </xsl:when>
         <xsl:otherwise>
          <xsl:value-of select="$day"/>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:variable>
   
     <xsl:choose>
       <xsl:when test="$alternative-day mod 7 = 0">
         <xsl:value-of select="$alternative-day + 1"/>
       </xsl:when>
       <xsl:when test="$alternative-day mod 7 =3">
         <xsl:value-of select="$alternative-day + 1"/>
       </xsl:when>
       <xsl:when test="$alternative-day mod 7 = 5">
         <xsl:value-of select="$alternative-day + 1"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="$alternative-day"/>
       </xsl:otherwise>
     </xsl:choose> 
     
</xsl:template>
<xsl:template name="ckbk:days-in-hebrew-year">
     <xsl:param name="year"/>
     
     <xsl:variable name="e1">
       <xsl:call-template name="ckbk:hebrew-calendar-elapsed-days">
         <xsl:with-param name="year" select="$year + 1"/>
       </xsl:call-template>
     </xsl:variable>
   
     <xsl:variable name="e2">
       <xsl:call-template name="ckbk:hebrew-calendar-elapsed-days">
         <xsl:with-param name="year" select="$year"/>
       </xsl:call-template>
     </xsl:variable>
     
     <xsl:value-of select="$e1 - $e2"/>
</xsl:template>
<xsl:template name="ckbk:long-heshvan">
     <xsl:param name="year"/>
     
     <xsl:variable name="days">
          <xsl:call-template name="ckbk:days-in-hebrew-year">
               <xsl:with-param name="year" select="$year"/>
          </xsl:call-template>
     </xsl:variable>
   
     <xsl:if select="$days mod 10 = 5">
          <xsl:value-of select="true(  )"/>
     </xsl:if>
</xsl:template>
   
<xsl:template name="ckbk:short-kislev">
     <xsl:param name="year"/>
   
     <xsl:variable name="days">
          <xsl:call-template name="ckbk:days-in-hebrew-year">
               <xsl:with-param name="year" select="$year"/>
          </xsl:call-template>
     </xsl:variable>
   
     <xsl:if select="$days mod 10 = 3">
          <xsl:value-of select="true(  )"/>
     </xsl:if>
</xsl:template>


<xsl:template name="ckbk:last-day-of-hebrew-month">
     <xsl:param name="month"/>
     <xsl:param name="year"/>
     
     <xsl:variable name="hebrew-leap-year" 
          select="(7 * $year + 1) mod 19 &lt; 7"/>
     
     <xsl:variable name="long-heshvan">
       <xsl:call-template name="ckbk:long-heshvan">
         <xsl:with-param name="year" select="$year"/>
       </xsl:call-template>
     </xsl:variable>
   
     <xsl:variable name="short-kislev">
       <xsl:call-template name="ckbk:short-kislev">
         <xsl:with-param name="year" select="$year"/>
       </xsl:call-template>
     </xsl:variable>
     
     <xsl:choose>
       <xsl:when test="$month=12 and $hebrew-leap-year">
         <xsl:value-of select="30"/>
       </xsl:when>
       <xsl:when test="$month=8 and string($long-heshvan)">
         <xsl:value-of select="30"/>
       </xsl:when>
       <xsl:when test="$month=9 and string($short-kislev)">
         <xsl:value-of select="29"/>
       </xsl:when>
       <xsl:when test="$month=13">
         <xsl:value-of select="29"/>
       </xsl:when>
       <xsl:when test="$month mod 2 = 0">
         <xsl:value-of select="29"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="30"/>
       </xsl:otherwise>
     </xsl:choose>
</xsl:template>
<xsl:template name="ckbk:sum-last-day-in-hebrew-months">
     <xsl:param name="year"/>
     <xsl:param name="from-month"/>
     <xsl:param name="to-month"/>
     <xsl:param name="accum" select="0"/>
   
     <xsl:choose>
       <xsl:when test="$from-month &lt;= $to-month">
         <xsl:call-template name="ckbk:sum-last-day-in-hebrew-months">
          <xsl:with-param name="year" select="$year"/>
          <xsl:with-param name="from-month" select="$from-month+1"/>
          <xsl:with-param name="to-month" select="$to-month"/>
          <xsl:with-param name="accum">
            <xsl:variable name="temp">
              <xsl:call-template name="ckbk:last-day-of-hebrew-month">
               <xsl:with-param name="year" select="$year"/>
               <xsl:with-param name="month" select="$from-month"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:value-of select="$temp + $accum"/>
          </xsl:with-param>
         </xsl:call-template>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="$accum"/>
       </xsl:otherwise>
     </xsl:choose>     
</xsl:template>
   
<xsl:template name="ckbk:hebrew-date-to-absolute-day">
    <xsl:param name="year"/>
    <xsl:param name="month"/>
    <xsl:param name="day"/>
   
     <xsl:variable name="prior-months-days">
       <xsl:choose>
         <xsl:when test="7 > $month"> <!-- before Tishri -->
          <xsl:variable name="last-month-of-year">
            <xsl:call-template name="ckbk:last-month-of-hebrew-year">
              <xsl:with-param name="year" select="$year"/>
            </xsl:call-template>
          </xsl:variable>
          <!-- Add days before and after Nisan -->
          <xsl:variable name="days-before-nisan">
            <xsl:call-template name="ckbk:sum-last-day-in-hebrew-months">
              <xsl:with-param name="year" select="$year"/>
              <xsl:with-param name="from-month" select="7"/>
              <xsl:with-param name="to-month" 
               select="$last-month-of-year"/>
            </xsl:call-template>
          </xsl:variable>
          <xsl:call-template name="ckbk:sum-last-day-in-hebrew-months">
            <xsl:with-param name="year" select="$year"/>
            <xsl:with-param name="from-month" select="1"/>
            <xsl:with-param name="to-month" select="$month - 1"/>
            <xsl:with-param name="accum" select="$days-before-nisan"/>
          </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
          <!-- days in prior months this year-->
          <xsl:call-template name="ckbk:sum-last-day-in-hebrew-months">
            <xsl:with-param name="year" select="$year"/>
            <xsl:with-param name="from-month" select="7"/>
            <xsl:with-param name="to-month" select="$month - 1"/>
          </xsl:call-template>
         </xsl:otherwise>
       </xsl:choose>    
     </xsl:variable>
     
     <xsl:variable name="days-in-prior-years">
       <xsl:call-template name="ckbk:hebrew-calendar-elapsed-days">
         <xsl:with-param name="year" select="$year"/>
       </xsl:call-template>
     </xsl:variable>
   
     <!--      1373429 days before absolute day 1 -->
     <xsl:value-of select="$day + $prior-months-days + 
          $days-in-prior-years - 1373429"/>
</xsl:template>
<xsl:template name="ckbk:fixup-hebrew-year">
     <xsl:param name="start-year"/>
     <xsl:param name="abs-day"/>
   
     <xsl:param name="accum" select="0"/>
   
     <xsl:variable name="next">
       <xsl:call-template name="ckbk:hebrew-date-to-absolute-day">
         <xsl:with-param name="month" select="7"/>
         <xsl:with-param name="day" select="1"/>
         <xsl:with-param name="year" select="$start-year + 1"/>
       </xsl:call-template>
     </xsl:variable>
     
     <xsl:choose>
       <xsl:when test="$abs-day >= $next">
         <xsl:call-template name="ckbk:fixup-hebrew-year">
          <xsl:with-param name="start-year" select="$start-year+1"/>
          <xsl:with-param name="abs-day" select="$abs-day"/>
          <xsl:with-param name="accum" select="$accum + 1"/>
         </xsl:call-template>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="$accum"/>
       </xsl:otherwise>
     </xsl:choose>     
</xsl:template>
   
<xsl:template name="ckbk:fixup-hebrew-month">
     <xsl:param name="year"/>
     <xsl:param name="start-month"/>
     <xsl:param name="abs-day"/>
   
     <xsl:param name="accum" select="0"/>
   
     <xsl:variable name="next">
       <xsl:call-template name="ckbk:hebrew-date-to-absolute-day">
         <xsl:with-param name="month" select="$start-month"/>
         <xsl:with-param name="day">
           <xsl:call-template name="ckbk:last-day-of-hebrew-month">
            <xsl:with-param name="month" select="$start-month"/>
            <xsl:with-param name="year" select="$year"/>
           </xsl:call-template>
         </xsl:with-param>
         <xsl:with-param name="year" select="$year"/>
       </xsl:call-template>
     </xsl:variable>
   
     <xsl:choose>
       <xsl:when test="$abs-day > $next">
         <xsl:call-template name="ckbk:fixup-hebrew-month">
          <xsl:with-param name="year" select="$year"/>
          <xsl:with-param name="start-month" select="$start-month + 1"/>
          <xsl:with-param name="abs-day" select="$abs-day"/>
          <xsl:with-param name="accum" select="$accum + 1"/>
         </xsl:call-template>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="$accum"/>
       </xsl:otherwise>
     </xsl:choose>     
</xsl:template>
   
<xsl:template name="ckbk:absolute-day-to-hebrew-date">
    <xsl:param name="abs-day"/>
   
     <xsl:variable name="year">
       <xsl:variable name="approx" 
          select="floor(($abs-day + 1373429) div 366)"/>
       <xsl:variable name="fixup">
         <xsl:call-template name="ckbk:fixup-hebrew-year">
           <xsl:with-param name="start-year" select="$approx"/>
           <xsl:with-param name="abs-day" select="$abs-day"/>
         </xsl:call-template>
       </xsl:variable>
       <xsl:value-of select="$approx + $fixup"/>
     </xsl:variable>
   
     <xsl:variable name="month">
       <xsl:variable name="first-day-of-year">
       <xsl:call-template name="ckbk:hebrew-date-to-absolute-day">
         <xsl:with-param name="month" select="1"/>
          <xsl:with-param name="day" select="1"/>
          <xsl:with-param name="year" select="$year"/>
         </xsl:call-template>
       </xsl:variable>
          
       <xsl:variable name="approx">
         <xsl:choose>
          <xsl:when test="$abs-day &lt; $first-day-of-year">
            <xsl:value-of select="7"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="1"/>
          </xsl:otherwise>
         </xsl:choose>
       </xsl:variable>
   
       <xsl:variable name="fixup">
         <xsl:call-template name="ckbk:fixup-hebrew-month">
          <xsl:with-param name="year" select="$year"/>
          <xsl:with-param name="start-month" select="$approx"/>
          <xsl:with-param name="abs-day" select="$abs-day"/>
         </xsl:call-template>
       </xsl:variable>
   
       <xsl:value-of select="$approx + $fixup"/>
     </xsl:variable>
   
     <xsl:variable name="day">
       <xsl:variable name="days-to-first-of-month">
         <xsl:call-template name="ckbk:hebrew-date-to-absolute-day">
           <xsl:with-param name="month" select="$month"/>
           <xsl:with-param name="day" select="1"/>
           <xsl:with-param name="year" select="$year"/>
         </xsl:call-template>
       </xsl:variable>
     
       <xsl:value-of select="$abs-day - ($days-to-first-of-month - 1)"/>
     </xsl:variable>
   
     <xsl:value-of select="concat($year,'-',$month,'-',$day)"/>
          
</xsl:template>
10) Formatting Dates and Times
<xsl:template name="ckbk:format-date-time">
    <xsl:param name="year"/>
    <xsl:param name="month"/>
    <xsl:param name="day"/>
    <xsl:param name="hour"/>
    <xsl:param name="minute"/>
    <xsl:param name="second"/>
    <xsl:param name="time-zone"/>
    <xsl:param name="format" select="'%Y-%m-%dT%H:%M:%S%z'"/>
   
     <xsl:choose>
       <xsl:when test="contains($format, '%')">
        <xsl:value-of select="substring-before($format, '%')"/>
      </xsl:when>
       <xsl:otherwise>
        <xsl:value-of select="$format"/>
       </xsl:otherwise>
     </xsl:choose>
   
    <xsl:variable name="code"
                  select="substring(substring-after($format, '%'), 1, 1)"/>
    <xsl:choose>
   
      <!-- Abbreviated weekday name -->
      <xsl:when test="$code='a'">
        <xsl:variable name="day-of-the-week">
          <xsl:call-template name="ckbk:calculate-day-of-the-week">
            <xsl:with-param name="year" select="$year"/>
            <xsl:with-param name="month" select="$month"/>
            <xsl:with-param name="day" select="$day"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:call-template name="ckbk:get-day-of-the-week-abbreviation">
          <xsl:with-param name="day-of-the-week" 
             select="$day-of-the-week"/>
        </xsl:call-template>
      </xsl:when>
   
      <!-- Full weekday name -->
      <xsl:when test="$code='A'">
        <xsl:variable name="day-of-the-week">
          <xsl:call-template name="ckbk:calculate-day-of-the-week">
            <xsl:with-param name="year" select="$year"/>
            <xsl:with-param name="month" select="$month"/>
            <xsl:with-param name="day" select="$day"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:call-template name="ckbk:get-day-of-the-week-name">
          <xsl:with-param name="day-of-the-week" 
                          select="$day-of-the-week"/>
        </xsl:call-template>
      </xsl:when>
   
      <!-- Abbreviated month name -->
      <xsl:when test="$code='b'">
        <xsl:call-template name="ckbk:get-month-abbreviation">
          <xsl:with-param name="month" select="$month"/>
        </xsl:call-template>
      </xsl:when>
   
      <!-- Full month name -->
      <xsl:when test="$code='B'">
        <xsl:call-template name="ckbk:get-month-name">
          <xsl:with-param name="month" select="$month"/>
        </xsl:call-template>
      </xsl:when>
   
      <!-- Date and time representation appropriate for locale -->
      <xsl:when test="$code='c'">
        <xsl:text>[not implemented]</xsl:text>
      </xsl:when>
   
      <!-- Day of month as decimal number (01 - 31) -->
      <xsl:when test="$code='d'">
        <xsl:value-of select="format-number($day,'00')"/>
      </xsl:when>
   
      <!-- Hour in 24-hour format (00 - 23) -->
      <xsl:when test="$code='H'">
        <xsl:value-of select="format-number($hour,'00')"/>
      </xsl:when>
   
      <!-- Hour in 12-hour format (01 - 12) -->
      <xsl:when test="$code='I'">
        <xsl:choose>
          <xsl:when test="$hour = 0">12</xsl:when>
          <xsl:when test="$hour &lt; 13">
            <xsl:value-of select="format-number($hour,'00')"/>
           </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="format-number($hour - 12,'00')"/>
         </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
   
      <!-- Day of year as decimal number (001 - 366) -->
      <xsl:when test="$code='j'">
         <xsl:variable name="diff"> 
         <xsl:call-template name="ckbk:date-difference">
           <xsl:with-param name="from-year" select="$year"/>
            <xsl:with-param name="from-month" select="1"/>
            <xsl:with-param name="form-day" select="1"/>
            <xsl:with-param name="to-year" select="$year"/>
            <xsl:with-param name="to-month" select="$month"/>
            <xsl:with-param name="to-day" select="$day"/>
         </xsl:call-template>
         </xsl:variable> 
        <xsl:value-of select="format-number($diff + 1, '000')"/>
      </xsl:when>
   
      <!-- Month as decimal number (01 - 12) -->
      <xsl:when test="$code='m'">
        <xsl:value-of select="format-number($month,'00')"/>
      </xsl:when>
   
      <!-- Minute as decimal number (00 - 59) -->
      <xsl:when test="$code='M'">
        <xsl:value-of select="format-number($minute,'00')"/>
      </xsl:when>
   
      <!-- Current locale's A.M./P.M. indicator for 12-hour clock -->
      <xsl:when test="$code='p'">
        <xsl:choose>
          <xsl:when test="$hour &lt; 12">AM</xsl:when>
          <xsl:otherwise>PM</xsl:otherwise>
        </xsl:choose>
      </xsl:when>
   
      <!-- Second as decimal number (00 - 59) -->
      <xsl:when test="$code='S'">
        <xsl:value-of select="format-number($second,'00')"/>
      </xsl:when>
   
      <!-- Week of year as decimal number, 
           with Sunday as first day of week (00 - 53) -->
      <xsl:when test="$code='U'">
        <!-- add 1 to day -->
        <xsl:call-template name="ckbk:calculate-week-number">
          <xsl:with-param name="year" select="$year"/>
          <xsl:with-param name="month" select="$month"/>
          <xsl:with-param name="day" select="$day + 1"/>
        </xsl:call-template>
      </xsl:when>
   
      <!-- Weekday as decimal number (0 - 6; Sunday is 0) -->
      <xsl:when test="$code='w'">
        <xsl:call-template name="ckbk:calculate-day-of-the-week">
          <xsl:with-param name="year" select="$year"/>
          <xsl:with-param name="month" select="$month"/>
          <xsl:with-param name="day" select="$day"/>
        </xsl:call-template>
      </xsl:when>
   
      <!-- Week of year as decimal number, 
           with Monday as first day of week (00 - 53) -->
      <xsl:when test="$code='W'">
        <xsl:call-template name="ckbk:calculate-week-number">
          <xsl:with-param name="year" select="$year"/>
          <xsl:with-param name="month" select="$month"/>
          <xsl:with-param name="day" select="$day"/>
        </xsl:call-template>
      </xsl:when>
   
      <!-- Date representation for current locale -->
      <xsl:when test="$code='x'">
        <xsl:text>[not implemented]</xsl:text>
      </xsl:when>
   
      <!-- Time representation for current locale -->
      <xsl:when test="$code='X'">
        <xsl:text>[not implemented]</xsl:text>
      </xsl:when>
   
      <!-- Year without century, as decimal number (00 - 99) -->
      <xsl:when test="$code='y'">
        <xsl:value-of select="format-number($year mod 100,'00')"/>  
      </xsl:when>
   
      <!-- Year with century, as decimal number -->
      <xsl:when test="$code='Y'">
         <xsl:value-of select="format-number($year,'0000')"/>
      </xsl:when>
   
      <!-- Time-zone name or abbreviation; -->
      <!-- no characters if time zone is unknown -->
      <xsl:when test="$code='z'">
        <xsl:value-of select="$time-zone"/>
      </xsl:when>
   
      <!-- Percent sign -->
      <xsl:when test="$code='%'">
        <xsl:text>%</xsl:text>
      </xsl:when>
   
    </xsl:choose>
   
    <xsl:variable name="remainder" 
                  select="substring(substring-after($format, '%'), 2)"/>
   
    <xsl:if test="$remainder">
      <xsl:call-template name="ckbk:format-date-time">
        <xsl:with-param name="year" select="$year"/>
        <xsl:with-param name="month" select="$month"/>
        <xsl:with-param name="day" select="$day"/>
        <xsl:with-param name="hour" select="$hour"/>
        <xsl:with-param name="minute" select="$minute"/>
        <xsl:with-param name="second" select="$second"/>
        <xsl:with-param name="time-zone" select="$time-zone"/>
        <xsl:with-param name="format" select="$remainder"/>
      </xsl:call-template>
    </xsl:if>
   
</xsl:template>
   
<xsl:template name="ckbk:format-julian-day">
    <xsl:param name="julian-day"/>
    <xsl:param name="format" select="'%Y-%m-%d'"/>
   
    <xsl:variable name="a" select="$julian-day + 32044"/>
    <xsl:variable name="b" select="floor((4 * $a + 3) div 146097)"/>
    <xsl:variable name="c" select="$a - floor(($b * 146097) div 4)"/>
   
    <xsl:variable name="d" select="floor((4 * $c + 3) div 1461)"/>
    <xsl:variable name="e" select="$c - floor((1461 * $d) div 4)"/>
    <xsl:variable name="m" select="floor((5 * $e + 2) div 153)"/>
   
    <xsl:variable name="day" select="$e - floor((153 * $m + 2) div 5) + 1"/>
    <xsl:variable name="month" select="$m + 3 - 12 * floor($m div 10)"/>
    <xsl:variable name="year" select="$b * 100 + $d - 4800 + floor($m div 10)"/>
   
    <xsl:call-template name="ckbk:format-date-time">
      <xsl:with-param name="year" select="$year"/>
      <xsl:with-param name="month" select="$month"/>
      <xsl:with-param name="day" select="$day"/>
      <xsl:with-param name="format" select="$format"/>
    </xsl:call-template>
   
</xsl:template>
XSLT 2.0
xsl:param name="date" as="xs:string"/>

<invoiceDate><xsl:value-of 
	select="format-date(
     xs:date(concat(substring($date,1,4),
                    '-',
                     substring($date,5,2),
                    '-',
                     substring($date,7,2))), 
              '[MNn] [D01], [Y0001]')"/></invoiceDate>
<invoiceDate>August 11, 2005</invoiceDate>
XSLT 2.0
format-dateTime($value as xs:dateTime?, 
                $picture as xs:string, 
                $date-format-name as xs:string) as xs:string?

format-dateTime($value as xs:dateTime?, $picture as xs:string) as xs:string? 

format-date($value as xs:date?,
            $picture as xs:string,
            $date-format-name as xs:string) as xs:string?

format-date($value as xs:date?, $picture as xs:string) as xs:string? 

format-time($value as xs:time?,
            $picture as xs:string,
            $date-format-name as xs:string) as xs:string?

format-time($value as xs:time?, $picture as xs:string) as xs:string? 
The date-format declaration
<!-- Category: declaration --> 
<xsl:date-format name = qname 
                 language = nmtoken 
                 calendar = qname />
<!-- Example: Thai --> 
<xsl:date-format name="modern_Thai" language="th" calendar="BE"/>
format-date($d, "[D&#x0E51;] [Mn] [Y&#x0E51;]", "modern_Thai")

<!--Example: Islamic--> 
<xsl:date-format name="Islamic" language="ar" calendar="AH"/>
format-date($d, "[D&#x0661;] [Mn] [Y&#x0661;]", "Islamic")

<!--Example: Jewish--> 
<xsl:date-format name="Jewish" language="he" calendar="AM"/>
format-date($d, "[D] [Mn] [Y]", "Jewish")
11) Determining Secular and Religious 
Holidays
<xsl:template name="ckbk:independence-day">
     <xsl:param name="year"/>
     <xsl:call-template name="ckbk:date-to-absolute-day">
          <xsl:with-param name="month" select="7"/>
          <xsl:with-param name="day" select="4"/>
          <xsl:with-param name="year" select="$year"/>
     </xsl:call-template>
</xsl:template>
<xsl:template name="ckbk:n-th-k-day">
    <!-- The n'th occurance of k in the given month -->
     <!-- Postive n counts from beginning of month; negative from end. -->
     <xsl:param name="n"/>   
   
    <!-- k = the day of the week (0 = Sun) -->     
     <xsl:param name="k"/>   
   
     <xsl:param name="month"/>
     <xsl:param name="year"/>
   
     <xsl:choose>
       <xsl:when test="$n > 0">
         <xsl:variable name="k-day-on-or-before">
          <xsl:variable name="abs-day">
            <xsl:call-template name="ckbk:date-to-absolute-day">
              <xsl:with-param name="month" select="$month"/>
              <xsl:with-param name="day" select="7"/>
              <xsl:with-param name="year" select="$year"/>
            </xsl:call-template>
          </xsl:variable>
          <xsl:call-template name="ckbk:k-day-on-or-before-abs-day">
            <xsl:with-param name="abs-day" select="$abs-day"/>
            <xsl:with-param name="k" select="$k"/>
          </xsl:call-template>
         </xsl:variable>
         <xsl:value-of select="$k-day-on-or-before + 7 * ($n - 1)"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:variable name="k-day-on-or-before">
          <xsl:variable name="abs-day">
            <xsl:call-template name="ckbk:date-to-absolute-day">
              <xsl:with-param name="month" select="$month"/>
              <xsl:with-param name="day">
               <xsl:call-template name="ckbk:last-day-of-month">
                 <xsl:with-param name="month" select="$month"/>
                 <xsl:with-param name="year" select="$year"/>
               </xsl:call-template>
              </xsl:with-param>
              <xsl:with-param name="year" select="$year"/>
            </xsl:call-template>
          </xsl:variable>
          <xsl:call-template name="ckbk:k-day-on-or-before-abs-day">
            <xsl:with-param name="abs-day" select="$abs-day"/>
            <xsl:with-param name="k" select="$k"/>
          </xsl:call-template>
         </xsl:variable>
         <xsl:value-of select="$k-day-on-or-before + 7 * ($n + 1)"/>
       </xsl:otherwise>
     </xsl:choose>
  </xsl:template>
<xsl:template name="ckbk:labor-day">
     <xsl:param name="year"/>
     <xsl:call-template name="ckbk:n-th-k-day ">
          <xsl:with-param name="n" select="1"/>
          <xsl:with-param name="k" select="1"/>
          <xsl:with-param name="month" select="9"/>
          <xsl:with-param name="year" select="$year"/>
     </xsl:call-template>
</xsl:template>
   
<xsl:template name="ckbk:memorial-day">
     <xsl:param name="year"/>
     <xsl:call-template name="ckbk:n-th-k-day ">
          <xsl:with-param name="n" select="-1"/>
          <xsl:with-param name="k" select="1"/>
          <xsl:with-param name="month" select="5"/>
          <xsl:with-param name="year" select="$year"/>
     </xsl:call-template>
</xsl:template>
<xsl:template name="ckbk:day-light-savings-start">
     <xsl:param name="year"/>
     <xsl:call-template name="ckbk:n-th-k-day ">
          <xsl:with-param name="n" select="1"/>
          <xsl:with-param name="k" select="0"/>
          <xsl:with-param name="month" select="4"/>
          <xsl:with-param name="year" select="$year"/>
     </xsl:call-template>
</xsl:template>
   
<xsl:template name="ckbk:day-light-savings-end">
     <xsl:param name="year"/>
     <xsl:call-template name="ckbk:n-th-k-day ">
          <xsl:with-param name="n" select="-1"/>
          <xsl:with-param name="k" select="0"/>
          <xsl:with-param name="month" select="10"/>
          <xsl:with-param name="year" select="$year"/>
     </xsl:call-template>
</xsl:template>

 
 
 
 
24		Dates and Times
11) Determining Secular and Religious Holidays		25 of 25
24
			25
DRAFT	O'Reilly & Associates	1/16/2006
